package bTree.LeetCode;

import java.util.*;

public class 字母异位词分组 {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> hashMap=new HashMap<>();
        for (String str : strs) {
            char[] charArray = str.toCharArray();
            Arrays.sort(charArray);
            String string = Arrays.toString(charArray);
            if(hashMap.containsKey(string)){
                List list = hashMap.get(string);
                list.add(str);
            }else {
                List<String>list=new ArrayList<>();
                list.add(str);
                hashMap.put(string,list);
            }
        }

        return new ArrayList<>(hashMap.values());
    }
}
